package com.kin207.netty.message.http.util;

import org.apache.commons.lang3.StringUtils;

import com.kin207.netty.message.http.util.DateUtil;

public class MessageAssembleUtil {
	
	private static String index = "680201";
	private static String serviceType ="0001";
	private static String flag="34";
	private static String longflag="35";
	private static String datalength = "05";
	private static String end="0016";
	
	public static String openAssemble(String deviceId,String first) {
		String flg = flag;
		System.out.println("openAssemble--->first:"+first);
		if(first.equals("0")) {
			flg = longflag;
			first = StringUtils.leftPad(first, 2, "0");
		}else if(first.equals("1")) {
			flg = longflag;
			first = StringUtils.leftPad(first, 2, "0");
		}else {
			flg = "34";
			first ="00";
		}
		String time = Integer.toHexString(DateUtil.getNowTime());
		StringBuffer openBuf =  new StringBuffer(index);
		openBuf.append(deviceId).append(Math.round((Math.random()+1) * 1000));
		openBuf.append(serviceType);
		openBuf.append(time).append("0007").append(flg).append(datalength);
		openBuf.append(first).append(time).append(end);
		return openBuf.toString();
	}

}
